import request from '@/utils/request';
import type { BasicMsg, BasicMsgWithData, Comment, CreateCommentRequest } from '@/types';

// 获取所有评论
export const getAllComments = (): Promise<BasicMsgWithData<Comment[]>> => {
  return request({
    url: '/api/comments',
    method: 'get'
  });
};

// 根据ID获取评论
export const getCommentById = (id: number): Promise<BasicMsgWithData<Comment>> => {
  return request({
    url: `/api/comments/${id}`,
    method: 'get'
  });
};

// 创建评论（需要订单）
export const createComment = (data: CreateCommentRequest): Promise<BasicMsg> => {
  return request({
    url: '/api/comments',
    method: 'post',
    data
  });
};

// 直接对菜品评论（不需要订单）
export const createDishComment = (data: CreateCommentRequest): Promise<BasicMsg> => {
  return request({
    url: '/api/comments/dish',
    method: 'post',
    data
  });
};

// 删除评论
export const deleteComment = (id: number): Promise<BasicMsg> => {
  return request({
    url: `/api/comments/${id}`,
    method: 'delete'
  });
};

// 根据菜品ID获取评论
export const getCommentsByDishId = (dishId: number): Promise<BasicMsgWithData<Comment[]>> => {
  return request({
    url: `/api/comments/dish/${dishId}`,
    method: 'get'
  });
};

// 根据用户ID获取评论
export const getCommentsByUserId = (userId: number): Promise<BasicMsgWithData<Comment[]>> => {
  return request({
    url: `/api/comments/user/${userId}`,
    method: 'get'
  });
};

// 根据订单ID获取评论
export const getCommentsByOrderId = (orderId: number): Promise<BasicMsgWithData<Comment[]>> => {
  return request({
    url: `/api/comments/order/${orderId}`,
    method: 'get'
  });
};

// 切换评论状态
export const toggleCommentStatus = (id: number, status: string): Promise<BasicMsg> => {
  return request({
    url: `/api/comments/toggle-status/${id}`,
    method: 'post',
    params: { status }
  });
};

